//package com.lt.test.consumer.controller;
//
//import com.alibaba.dubbo.config.annotation.Reference;
//import com.lt.test.api.RedisService;
//import com.lt.test.api.ShopService;
//import com.lt.test.common.exception.CustomException;
//import com.lt.test.common.util.HttpClientUtil;
//import com.lt.test.entity.DTO.ResponseDTO;
//import com.lt.test.entity.DTO.SuperMarketUserDTO;
//import com.lt.test.entity.QueryModel.MapQueryModel;
//import net.sf.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Map;
//
///**
// * Created by zhengchuan on 2017/6/5.
// */
//@Controller
//@RequestMapping("/supermarket")
//public class SuperMarketController {
//    private static final Logger logger = LoggerFactory.getLogger(SuperMarketController.class);
//    private static String ServerPath = "http://10.95.0.233:8094";
//    @Reference(version = "1.0.0")
//    private RedisService redisService;
//    @Reference(version = "1.0.0")
//    private ShopService shopService;
//
//    /**
//     * 跳转到登陆页面
//     *
//     * @param request
//     * @param response
//     */
//    @RequestMapping("/login")
//    public String login(HttpServletRequest request, HttpServletResponse response) {
//        return "content/supermarket/login";
//    }
//
//    /**
//     * 跳转到登陆页面
//     *
//     * @param request
//     * @param response
//     */
//    @RequestMapping("/goToHome")
//    public String goToHome(HttpServletRequest request, HttpServletResponse response) throws CustomException {
//        String shopId = request.getParameter("shopId");
//        String userId = request.getParameter("userId");
//
//        SuperMarketUserDTO user  = new SuperMarketUserDTO();
////        user = (SuperMarketUserDTO) redisService.get(getLoginuserKey(shopId, userId));
//        user.setShopId(shopId);
//        user.setUserId(userId);
//        if (user == null || shopId == null || userId == null) {
//            return "content/supermarket/login";
//        }
//        user =  shopService.getShopAndUserByShopIdAndUserId(user);
//        request.setAttribute("user",user);
//        return "content/supermarket/home";
//    }
//
//
//    /**
//     * 获取订单状态
//     *
//     * @param request
//     */
//    @RequestMapping("/getOrderState")
//    public @ResponseBody
//    ResponseDTO getOrderState(HttpServletRequest request, String orderId) throws CustomException {
//        ResponseDTO responseDTO = new ResponseDTO();
//
//        Map<String,String> result  =  shopService.getOrderState(orderId);
//        responseDTO.setData(result);
//        responseDTO.setSuccess(true);
//        responseDTO.setMessage("获取成功");
//        return responseDTO;
//    }
//
//    /**
//     * 登陆 - 判断是否扫描二维码
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping(value = "/getQRCodeLoginResult" ,produces = "application/json; charset=utf-8")
//    public @ResponseBody
//    String getQRCodeLoginResult(HttpServletRequest request, HttpServletResponse response, String randNumber) {
//        String url ="http://10.95.0.233:23912/clouderp-shop-rest/api/shop/findRandNumber?randNumber="+randNumber;
//        String responseResult = HttpClientUtil.sendGetRequest(url,null);
//        JSONObject jsonObject = JSONObject.fromObject(responseResult);
//        if (jsonObject != null && !jsonObject.isEmpty() && jsonObject.get("data") != null && !"null".equals(jsonObject.get("data").toString())){ //有人扫码了
//            JSONObject data = JSONObject.fromObject(jsonObject.get("data"));
//            SuperMarketUserDTO superMarketUserDTO = new SuperMarketUserDTO();
//            superMarketUserDTO.setUserId(data.get("userId").toString());
//            superMarketUserDTO.setShopId(data.get("shopId").toString());
//
//            redisService.set(getLoginuserKey(superMarketUserDTO.getShopId(),superMarketUserDTO.getUserId()),superMarketUserDTO,86400L);
//
//        }
//        //System.out.println(responseResult);
//        return responseResult;
//    }
//
//    /**
//     * get方法代理
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping(value = "/httpGet" ,produces = "application/json; charset=utf-8")
//    public @ResponseBody
//    String httpGet(HttpServletRequest request, HttpServletResponse response, String url) {
//        try {
//            String responseResult = HttpClientUtil.sendGetRequest(url,null);
//            logger.info("社区云超市-Get代理请求：url : "+url+", result : "+responseResult);
//            return responseResult;
//        }catch (Exception e) {
//            e.printStackTrace();
//            logger.error("社区云超市-代理请求：url : "+url);
//            return "{'success':'error'}";
//        }
//    }
//
//    /**
//     * post方法代理
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequestMapping(value = "/httpPost" ,produces = "application/json; charset=utf-8")
//    public @ResponseBody
//    String httpPost(HttpServletRequest request, HttpServletResponse response, MapQueryModel params, String url) {
//        System.out.println("=========> url:"+url);
//        System.out.println("=========> params:"+params);
//        try {
//            String responseResult = HttpClientUtil.sendPostRequest(url, params.getStringMap(), null, null);
//            System.out.println("社区云超市-Post代理请求：url : "+url+", params : "+params.getStringMap()+", result : "+responseResult);
//            System.out.println("=========> responseResult :"+responseResult);
//            return responseResult;
//        }catch (Exception e) {
//            e.printStackTrace();
//            System.out.println("社区云超市-Post代理请求：url : "+url+", params : "+params.getStringMap());
//            return "{'success':'error'}";
//        }
//    }
//
//    private final String getLoginuserKey(String shopId, String userId) {
//        final String SUPER_MARKET_LOGIN_USER_KEY = "SUPER_MARKET_LOGIN_USER_KEY|"+shopId+"|"+userId;
//        return  SUPER_MARKET_LOGIN_USER_KEY;
//    }
//
//}
